<template>
    <div class="forum-list-wrap">
        <div class="banner">
            <el-carousel height="7.5rem">
                <el-carousel-item v-for="(item,index) in bannerList" :key="index">
                    <div class="banner-img" @click="clickBannerFun(item)">
                        <img :src="item.image" alt="" />
                    </div>
                </el-carousel-item>
            </el-carousel>
        </div>
        <div class="notice-body">
            <div class="notice-view">
                <div class="notice-title">
                    <div class="notice-title-left">
                        <span>公告</span>
                        <span class="notice-title-line"></span>
                        <span>NOTICE</span>
                    </div>
                    <div class="notice-title-right" @click="$router.replace('/notice-list')">
                        <span>查看更多</span>
                        <i class="el-icon-arrow-right"></i>
                    </div>
                </div>
                <div class="notice-main">
                    <div class="notice-main-left">
                        <template v-for="(item,index) in listNotice">
                            <template v-if="index < 4">
                                <div class="notice-item2" :key="index" v-if="index == 0" @click="toNoticeFun(item)">
                                    <img :src="item.thumb" alt="">
                                    <div class="notice-item2-bottom">
                                        <div class="notice-item2-title u-line-1">{{ item.title }}</div>
                                        <div class="notice-item2-time">{{ getDateComputed(item.created_at)  }}</div>
                                    </div>
                                </div>
                                <div class="notice-item" v-else :key="index" @click="toNoticeFun(item)">
                                    <div class="notice-view">
                                        <div class="notice-view-left">
                                            <div class="notice-view-font1">{{ getDateCusComputed(item.created_at,'MM.DD') }}</div>
                                            <div class="notice-view-font2">{{ getDateCusComputed(item.created_at,'YYYY') }}</div>
                                        </div>
                                        <div class="notice-view-right u-line-2">{{ item.title }}</div>
                                    </div>
                                </div>
                            </template>
                        </template>
                    </div>
                    <div class="notice-main-right">
                        <template v-for="(item,index) in listNotice">
                            <div class="notice-item" v-if="index >= 4" :key="index"  @click="toNoticeFun(item)">
                                <div class="notice-item-title u-line-1">{{ item.title }}</div>
                                <div class="notice-item-time">{{ getDateComputed(item.created_at) }}</div>
                            </div>
                        </template>
                    </div>
                </div>
            </div>
        </div>

        <div class="forum-body">
            <div class="forum-view">
                <div class="forum-title">
                    <div class="forum-title-left">
                        <span>论坛</span>
                        <span class="forum-title-line"></span>
                        <span>FORUM</span>
                    </div>
                    <div class="forum-title-right" @click="$router.replace('/forum-list')">
                        <span>查看更多</span>
                        <i class="el-icon-arrow-right"></i>
                    </div>
                </div>
                <div class="forum-main">
                    <div class="forum-banner">
                        <el-carousel height="5.9rem" indicator-position="none">
                            <el-carousel-item v-for="(item,index) in forumBannerList" :key="index">
                                <div class="forum-banner-img" @click="toForumFun(item)">
                                    <img :src="item.thumb" alt="" />
                                    <div class="forum-banner-bottom u-line-1">{{ item.title }}</div>
                                </div>
                            </el-carousel-item>
                        </el-carousel>
                    </div>
                    <div class="forum-center">
                        <div class="forum-center-item"  @click="toForumFun(item)" v-for="(item,index) in forumCenterList" :key="index">
                            <div class="forum-center-title u-line-1">{{ item.title }}</div>
                            <div class="forum-center-intro u-line-2">{{ item.description }}</div>
                            <div class="forum-center-bottom">
                                <span>{{ getDateComputed(item.created_at) }}</span>
                                <span class="forum-center-icon">
                                    <i class="el-icon-arrow-right"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="forum-right">
                        <div class="forum-right-item" @click="toForumFun(item)" v-for="(item,index) in forumList" :key="index">
                            <div class="forum-right-time">
                                <div class="forum-right-day">{{ getDateCusComputed(item.created_at,'DD') }}</div>
                                <div class="forum-right-year">{{ getDateCusComputed(item.created_at,'YYYY-MM') }}</div>
                            </div>
                            <div class="forum-right-content">
                                <div class="forum-right-title u-line-2">{{ item.title }}</div>
                                <div class="forum-right-bottom">
                                    <span class="el-icon-right"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="study-body">
            <div class="study-view">
                <div class="study-title">
                    <div class="study-title-left">
                        <span>知识库</span>
                        <span class="study-title-line"></span>
                        <span>KNOWLEDGE BASE</span>
                    </div>
                    <div class="study-title-right" @click="$router.replace('/study-list')">
                        <span>查看更多</span>
                        <i class="el-icon-arrow-right"></i>
                    </div>
                </div>
                <div class="study-list">
                    <div class="study-list-left">
                        <div class="study-item" @click="toStudyFun(item)" v-for="(item,index) in studyList1" :key="index">
                            <div class="study-item-left">
                                <div class="study-item-day">{{ getDateCusComputed(item.created_at,'MM.DD') }}</div>
                                <div class="study-item-year">{{ getDateCusComputed(item.created_at,'YYYY') }}</div>
                                <div>
                                    <div class="study-item-tip">合集</div>
                                </div>
                            </div>
                            <div class="study-item-right">
                                <div class="study-item-title u-line-2">{{ item.title }}</div>
                            </div>
                        </div>
                    </div>
                    <div class="study-list-right">
                        <div class="study-item" @click="toStudyFun(item)" v-for="(item,index) in studyList2" :key="index">
                            <div class="study-item-left">
                                <div class="study-item-day">{{ getDateCusComputed(item.created_at,'MM.DD') }}</div>
                                <div class="study-item-year">{{ getDateCusComputed(item.created_at,'YYYY') }}</div>
                                <div>
                                    <div class="study-item-tip">合集</div>
                                </div>
                            </div>
                            <div class="study-item-right">
                                <div class="study-item-title u-line-2">{{ item.title }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</template>

<script>

import {mustLogin,get_date} from "@/utils/utils"
import {getForumList} from "@/api/forum";
import {getNoticeList} from "@/api/notice";
import {getBanner} from "@/api/common";
import {getProductList} from "@/api/study"
export default {
    components: {

    },
    data() {
        return {
            bannerList: [],
            forumBannerList:[],
            forumCenterList:[],
            forumList:[],
            listNotice:[],
            studyList1:[],
            studyList2:[],
        };
    },
    computed:{
        getDateComputed(){
            return (date)=>{
                return get_date('YYYY-MM-DD',date)
            }
        },
        getDateCusComputed(){
            return (date,format)=>{
                return get_date(format,date)
            }
        }
    },
    mounted() {
        this.getBannerFun()
        this.getForumListFun()
        this.getNoticeFun()
        this.getStudyFun()
        this.getStudyFun2()
    },
    methods: {
        getBannerFun() {
            getBanner({
                position: 1
            }).then(res => {
                this.bannerList = res.data
            })
        },
        clickBannerFun(item){
            if(item.url){
                window.location.href = item.url
            }
        },
        toForumFun(item){
            this.$router.push({
                path:"/forum-detail/"+item.id
            })
        },
        getForumListFun() {
            getForumList({page:1,limit:8}).then((res) => {
                if(res.code == 200){
                    let {count,list} = res.data
                    this.forumBannerList = list.slice(0,3)
                    this.forumCenterList = list.slice(3,5)
                    this.forumList = list.slice(5)
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        getNoticeFun(){
            getNoticeList({page:1,limit:9}).then(res=>{
                if(res.code == 200){
                    let {count,list} = res.data
                    this.listNotice = list
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        toNoticeFun(item){
            this.$router.push({
                path:"/notice-detail/"+item.id
            })
        },
        getStudyFun(){
            getProductList({page:1,limit:3,type:1}).then(res=>{
                if(res.code == 200){
                    this.studyList1 = res.data.list
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        getStudyFun2(){
            getProductList({page:1,limit:3,type:2}).then(res=>{
                if(res.code == 200){
                    this.studyList2 = res.data.list
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        toStudyFun(item){
            this.$router.push({
                path:"/study-detail/"+item.id
            })
        },
    },
};
</script>

<style lang="less" scoped>
.forum-list-wrap {
    .banner {
        width: 100%;
        height: 7.5rem;
        .banner-img {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100%;
            cursor: pointer;
            img {
                width: 100%;
                height: 100%;
            }
        }
    }

    .notice-body{
        width: 100%;
        height: 12.9625rem;
        background-color: #00146E;
        background-image: url("@/assets/img/home-bg1.png");
        background-size: 31.1125rem 12.9625rem;
        background-repeat: no-repeat;
        background-position: center;
        .notice-view{
            width: 17.5rem;
            margin: 0 auto;
            .notice-title{
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding-top: 1.25rem;
                .notice-title-left{
                    display: flex;
                    align-items: center;
                    font-size: 0.375rem;
                    font-weight: 600;
                }
                .notice-title-line{
                    width: 0.075rem;
                    height: 0.375rem;
                    background: #4F8AF8;
                    margin: 0 0.125rem;
                    transform: rotate(15deg);
                }
                .notice-title-right{
                    font-size: 0.25rem;
                    color: #4F546B;
                    cursor: pointer;
                }
            }
            .notice-main{
                display: flex;
                justify-content: space-between;
                padding-top: .75rem;
                width: 100%;
                .notice-main-left{
                    .notice-item2{
                        position: relative;
                        width: 8.625rem;
                        height: 4.5rem;
                        display: flex;
                        cursor: pointer;
                        img{
                            width: 100%;
                            height: 100%;
                            object-fit: cover;
                        }
                        .notice-item2-bottom{
                            position: absolute;
                            bottom: 0;
                            display: flex;
                            justify-content: space-between;
                            align-items: center;
                            height: .7rem;
                            background-color: rgba(#000,0.32);
                            width: 100%;
                            font-size: .225rem;
                            color: #fff;
                            box-sizing: border-box;
                            padding: 0 .5rem;
                        }
                        .notice-item2-title{
                            width: 5.25rem;
                        }
                    }

                    .notice-item{
                        width: 100%;
                        background-color: #fff;
                        padding: 0 .5rem;
                        box-sizing: border-box;
                        .notice-view{
                            display: flex;
                            align-items: center;
                            width: 100%;
                            height: 1.4625rem;
                            border-bottom: .0125rem solid #D2D6DB;
                            cursor: pointer;
                            .notice-view-left{
                                width: 1.5rem;
                            }
                            .notice-view-right{
                                width: 6rem;
                                font-size: .2rem;
                                color: #000;
                                line-height: .3rem;
                            }
                            .notice-view-font1{
                                font-size: .35rem;
                                color: #4F8AF8;
                                line-height: .5rem;
                            }
                            .notice-view-font2{
                                font-size: .15rem;
                                color: #9FA6C2;
                            }
                        }
                    }
                }
                .notice-main-right{
                    .notice-item{
                        cursor: pointer;
                        display: flex;
                        justify-content: center;
                        flex-direction: column;
                        width: 8.625rem;
                        height: 1.575rem;
                        background-color: #fff;
                        padding: 0 .5rem;
                        box-sizing: border-box;
                        margin-bottom: .25rem;
                        .notice-item-title{
                            font-size: .2rem;
                            color: #000;
                        }
                        .notice-item-time{
                            font-size: .15rem;
                            color: #9FA6C2;
                            margin-top: .125rem;
                        }
                    }
                }
            }
        }
    }

    .forum-body{
        width: 100%;
        height: 10.05rem;
        background-color: #F8F8F8;
        .forum-view{
            width: 17.5rem;
            margin: 0 auto;
            .forum-title{
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding-top: 1.25rem;
                .forum-title-left{
                    display: flex;
                    align-items: center;
                    font-size: 0.375rem;
                    font-weight: 600;
                }
                .forum-title-line{
                    width: 0.075rem;
                    height: 0.375rem;
                    background: #4F8AF8;
                    margin: 0 0.125rem;
                    transform: rotate(15deg);
                }
                .forum-title-right{
                    font-size: 0.25rem;
                    color: #4F546B;
                    cursor: pointer;
                }
            }
            .forum-main{
                display: flex;
                padding-top: .75rem;
                .forum-banner{
                    width: 6.9rem;
                    height: 5.9rem;
                    margin-right: .3rem;
                    .forum-banner-img{
                        position: relative;
                        width: 100%;
                        height: 100%;
                        cursor: pointer;
                    }
                    .forum-banner-bottom{
                        position: absolute;
                        bottom: 0;
                        width: 100%;
                        height: .7rem;
                        z-index: 10;
                        background-color: rgba(#000,0.5);
                        box-sizing: border-box;
                        padding: 0 .25rem;
                        line-height: 0.7rem;
                        font-size: .225rem;
                        color: #fff;
                    }
                }
                .forum-center{
                    width: 5rem;
                    margin-right: .3rem;
                    .forum-center-item{
                        box-sizing: border-box;
                        background-color: #fff;
                        padding: .45rem .3375rem 0;
                        margin-bottom: .25rem;
                        cursor: pointer;
                        .forum-center-title{
                            font-size: .2rem;
                            color: #000;
                            line-height: .275rem;
                        }
                        .forum-center-intro{
                            font-size: .175rem;
                            height: .475rem;
                            line-height: .2375rem;
                            color: #9FA6C2;
                            margin-top: .125rem;
                            padding-bottom: .15rem;
                            border-bottom: .0125rem solid #D2D6DB;
                        }
                        .forum-center-bottom{
                            display: flex;
                            align-items: center;
                            justify-content: space-between;
                            font-size: .15rem;
                            color: #9FA6C2;
                            padding: .5rem 0;
                            .forum-center-icon{
                                width: .3rem;
                                height: .3rem;
                                background: #4F8AF8;
                                border-radius: 50%;
                                color: #fff;
                                text-align: center;
                                line-height: .3rem;
                            }
                        }
                    }
                }
                .forum-right{
                    width: 5rem;
                    .forum-right-item{
                        display: flex;
                        align-items: center;
                        width: 100%;
                        height: 1.8rem;
                        background-color: #fff;
                        box-sizing: border-box;
                        padding: 0 .3375rem;
                        margin-bottom: .25rem;
                        cursor: pointer;
                        .forum-right-time{
                            width: .9625rem;
                            .forum-right-day{
                                position: relative;
                                font-size: .4rem;
                                color: #4F8AF8;
                                line-height: .5625rem;
                                &::after{
                                    content: '';
                                    display: block;
                                    position: absolute;
                                    bottom: 0;
                                    width: .25rem;
                                    height: .0125rem;
                                    background-color: #D2D6DB;
                                }
                            }
                            .forum-right-year{
                                font-size: .15rem;
                                color: #9FA6C2;
                                padding-top: .125rem;
                            }
                        }
                        .forum-right-content{
                            border-left: .0125rem solid #D2D6DB;
                            flex: 1;
                            padding-left: .3375rem;
                        }
                        .forum-right-title{
                            font-size: .2rem;
                            color: #000;
                            line-height: .2875rem;
                        }
                        .forum-right-bottom{
                            color: #9FA6C2;
                            padding-top: .125rem;
                        }
                    }
                }
            }
        }
    }


    .study-body{
        width: 100%;
        height: 11.175rem;
        background-image: url("@/assets/img/home-bg2.png");
        background-size: 28.975rem 12.225rem;
        background-repeat: no-repeat;
        background-position: center;
        .study-view{
            width: 17.5rem;
            margin: 0 auto;
            .study-title{
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding-top: 1.25rem;
                .study-title-left{
                    display: flex;
                    align-items: center;
                    font-size: 0.375rem;
                    font-weight: 600;
                }
                .study-title-line{
                    width: 0.075rem;
                    height: 0.375rem;
                    background: #4F8AF8;
                    margin: 0 0.125rem;
                    transform: rotate(15deg);
                }
                .study-title-right{
                    font-size: 0.25rem;
                    color: #4F546B;
                    cursor: pointer;
                }
            }
            .study-list{
                display:flex;
                flex-wrap: wrap;
                justify-content: space-between;
                padding-top: .75rem;
                .study-item{
                    display: flex;
                    align-items: center;
                    width: 8.625rem;
                    height: 2.175rem;
                    background: #FFFFFF;
                    margin-bottom: .25rem;
                    .study-item-left{
                        position: relative;
                        width: 2.1625rem;
                        box-sizing: border-box;
                        padding-left: .5rem;
                        &::after{
                            content: '';
                            position: absolute;
                            right: 0;
                            top: 50%;
                            transform: translateY(-50%);
                            width: .0125rem;
                            height: .75rem;
                            background-color: #D2D6DB;
                        }
                        .study-item-day{
                            font-size: .4rem;
                            color: #4F8AF8;
                            line-height: .5625rem;
                        }
                        .study-item-year{
                            font-size: .15rem;
                            color: #9FA6C2;
                        }
                        .study-item-tip{
                            width: .6rem;
                            height: .275rem;
                            text-align: center;
                            line-height: .275rem;
                            border-radius: .05rem ;
                            border: .0125rem solid #9FA6C2;
                            font-size: .2rem;
                            color: #9FA6C2;
                            margin-top: .25rem;
                        }
                    }
                    .study-item-right{
                        width: 5.375rem;
                        padding-left: .5rem;
                    }
                    .study-item-title{
                        font-size: .2rem;
                        color: #000;
                        line-height: .2875rem;
                    }
                    .study-item-intro{
                        font-size: .175rem;
                        color: #9FA6C2;
                        margin-top: .175rem;
                    }
                }
            }
        }
    }
   
}
</style>